Skip to content

Optimization for shell sort #4038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 18, 2020
Merged

Optimization for shell sort #4038

merged 3 commits into from
Dec 18, 2020

Conversation

realDuYuanChao
Copy link
Member

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@ghost ghost added awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files labels Dec 16, 2020
@cclauss
Copy link
Member

cclauss commented Dec 16, 2020

I do not quite understand the title of this PR. In what way is the current implementation broken?

@realDuYuanChao
Copy link
Member Author

realDuYuanChao commented Dec 16, 2020

I do not quite understand the title of this PR. In what way is the current implementation broken?

We should insert value instead of swapping elements of array.

@realDuYuanChao realDuYuanChao changed the title Fixed shell sort Optimization for shell sort Dec 16, 2020
@l3str4nge
Copy link
Member

Is your implementation improve performance or what? If so please write proper tests for proof that your solution is better than already exists.

Copy link
Member

@l3str4nge l3str4nge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need additional tests for performance

@ghost ghost added awaiting changes A maintainer has requested changes to this PR and removed awaiting reviews This PR is ready to be reviewed labels Dec 16, 2020
@poyea
Copy link
Member

poyea commented Dec 16, 2020

Maybe we can strictly follow this?: https://en.wikipedia.org/wiki/Shellsort#Pseudocode
Sometimes it's just a matter of styles.

Copy link
Member

@poyea poyea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may add a reference to the wiki page as well.

@ghost ghost added awaiting reviews This PR is ready to be reviewed and removed awaiting changes A maintainer has requested changes to this PR labels Dec 17, 2020
@realDuYuanChao
Copy link
Member Author

@poyea Done. Please review again.

Comment on lines 1 to +2
"""
This is a pure Python implementation of the shell sort algorithm

For doctests run following command:
python -m doctest -v shell_sort.py
or
python3 -m doctest -v shell_sort.py

For manual testing run:
python shell_sort.py
https://en.wikipedia.org/wiki/Shellsort#Pseudocode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave the first line like this

Suggested change
"""
This is a pure Python implementation of the shell sort algorithm
For doctests run following command:
python -m doctest -v shell_sort.py
or
python3 -m doctest -v shell_sort.py
For manual testing run:
python shell_sort.py
https://en.wikipedia.org/wiki/Shellsort#Pseudocode
"""
This is a Python implementation of the shell sort algorithm.
Reference: https://en.wikipedia.org/wiki/Shellsort#Pseudocode

Copy link
Member

@poyea poyea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would approve this as the original version has really no reference to the algorithm (or at least, the implementation didn't strictly follow the algorithm). Thank you for your pull request!🤩

@ghost ghost removed the awaiting reviews This PR is ready to be reviewed label Dec 17, 2020
@ghost ghost added the awaiting reviews This PR is ready to be reviewed label Dec 18, 2020
@realDuYuanChao
Copy link
Member Author

@poyea Done

@realDuYuanChao
Copy link
Member Author

@mateuszz0000 Can you review again. Thanks :)

@l3str4nge l3str4nge merged commit 53371b2 into TheAlgorithms:master Dec 18, 2020
@ghost ghost removed the awaiting reviews This PR is ready to be reviewed label Dec 18, 2020
@realDuYuanChao realDuYuanChao deleted the ShellSort branch December 19, 2020 00:27
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* fixed shell sort

* udpate code style

* Update sorts/shell_sort.py

Co-authored-by: John Law <[email protected]>

Co-authored-by: John Law <[email protected]>
peRFectBeliever pushed a commit to peRFectBeliever/Python that referenced this pull request Apr 1, 2021
* fixed shell sort

* udpate code style

* Update sorts/shell_sort.py

Co-authored-by: John Law <[email protected]>

Co-authored-by: John Law <[email protected]>
Panquesito7 pushed a commit to Panquesito7/Python that referenced this pull request May 13, 2021
* fixed shell sort

* udpate code style

* Update sorts/shell_sort.py

Co-authored-by: John Law <[email protected]>

Co-authored-by: John Law <[email protected]>
shermanhui pushed a commit to shermanhui/Python that referenced this pull request Oct 22, 2021
* fixed shell sort

* udpate code style

* Update sorts/shell_sort.py

Co-authored-by: John Law <[email protected]>

Co-authored-by: John Law <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This PR modified some existing files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants